'use strict';
/**
 * Created by QianQi on 2017/5/18.
 */
$(function(){
    var oHideParams = $.getHideParams(),// <body> 下隐藏域键值对，name 为键
        oUrlParams = $.getUrlParams();// url 附加参数键值对
    var URLS = {};
    var jqLog = $('.js-log');// 日志容器

    // demo 日志输出
    var fLog = function(str){
        jqLog.prepend('<div>' + str + '</div>');
        console.log(str);
    };
    // 支持进度条内容重绘
    var fInRender = function(obj){
        return '<div class="loadingdata-in"><span style="color:#d9544f;">***</span>' + obj.content + '</div>';
    };
    var fMain = function(){
        var aTime = [],
            aOpts = [
                {
                    key: '0',
                    content: 'loading 0'
                }, {
                    key: '1',
                    content: 'loading 1'
                }, {
                    key: '2',
                    content: 'loading 2',
                    fInRender: fInRender
                }];
        for(var i = 0, t, opt, key; i < 3; i++){
            t = Math.floor(Math.random() * 10);
            opt = aOpts[i];
            key = opt.key;
            fLog('show:'+ key + ' ' + t + 's 后隐藏');
            t = t * 1000 + 500;// 转为 ms 并延迟 500ms
            aTime.push(t);
            $.showLoading(opt);
            setTimeout((function(sKey){
                return function(){
                    fLog('hide:' + sKey);
                    $.hideLoading({
                        key: sKey
                    });
                }
            })(key), t);
        }
    };
    /** =================== **/
    fMain();
});